package com.example.mylayoutparams;

import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_main);
        LinearLayout linearLayout=new LinearLayout(this);
        LinearLayout.LayoutParams layoutParams=new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
        linearLayout.setLayoutParams(layoutParams);
        TextView textView=new TextView(this);
        textView.setText("文本内容:csdn碰磕");
        textView.setBackgroundColor(0xffff0000);
        //直接赋值默认单位px
        LinearLayout.LayoutParams textlayoutParams=new LinearLayout.LayoutParams(300,300);
//        textView.setLayoutParams(textlayoutParams);
        linearLayout.addView(textView,textlayoutParams);
        setContentView(linearLayout);
    }
}
